//
//  YDUserBaseInfoEditViewController.m
//  IngCard
//
//  Created by kf on 2017/8/31.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDUserBaseInfoEditViewController.h"
#import "YDAccountManager.h"

@interface YDUserBaseInfoEditViewController ()

@property(nonatomic, strong) UIImageView *headerImageView;
@property(nonatomic, strong) UIButton *headerEditButton;

@property(nonatomic, strong) UILabel *familyNameLabel;
@property(nonatomic, strong) UITextField *familyNameTextField;

@property(nonatomic, strong) UILabel *lastNameLabel;
@property(nonatomic, strong) UITextField *lastNameTextField;

@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UITextField *titleTextField;

@property(nonatomic, strong) UILabel *companyLabel;
@property(nonatomic, strong) UITextField *companyTextField;

@property(nonatomic, strong) UILabel *emailLabel;
@property(nonatomic, strong) UITextField *emailTextField;

@property(nonatomic, strong) UILabel *locationLabel;
@property(nonatomic, strong) UITextField *locationTextFiled;

@end

@implementation YDUserBaseInfoEditViewController

- (void) viewDidLoad
{
    [super viewDidLoad];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"确定"
                                                                  style:UIBarButtonItemStyleDone
                                                                 target:self
                                                                 action:@selector(rightBarItemClick:)];
    rightItem.tintColor = UIColorMake(60, 44, 44);
    
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                                                 style:UIBarButtonItemStyleDone
                                                                target:self
                                                                action:@selector(rightBarItemClick:)];
    leftItem.tintColor = UIColorMake(60, 44, 44);
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Dark];
    [THEME renderNavigationBar:self style:YDNavigationStyle_Gray];
    
    [self.familyNameTextField becomeFirstResponder];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear: animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Light];
}

- (void) initSubviews
{
    [super initSubviews];

    self.title = STRING.user_edit_baseInfo;
    
    [self.view addSubview:self.headerImageView];
    [self.headerImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(83);
        make.centerX.equalTo(self.view);
    }];
    
    [self.view addSubview:self.headerEditButton];
    [self.headerEditButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerImageView.mas_bottom).offset(4);
        make.centerX.equalTo(self.view);
    }];
    
    [self.view addSubview:self.familyNameLabel];
    [self.familyNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(40);
        make.top.equalTo(214);
    }];
    
    [self.view addSubview:self.familyNameTextField];
    [self.familyNameTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.familyNameLabel.mas_right).offset(40);
        make.bottom.equalTo(self.familyNameLabel).offset(-1);
        make.width.equalTo(80);
    }];
    
    [self.view addSubview:self.lastNameLabel];
    [self.lastNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.familyNameTextField.mas_right).offset(18);
        make.top.equalTo(self.familyNameLabel);
    }];
    
    [self.view addSubview:self.lastNameTextField];
    [self.lastNameTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lastNameLabel.mas_right).offset(18);
        make.bottom.equalTo(self.familyNameTextField);
        make.width.equalTo(80);
    }];
    
    [self.view addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(36);
        make.top.equalTo(self.familyNameLabel.mas_bottom).offset(51);
    }];
    
    [self.view addSubview:self.titleTextField];
    [self.titleTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(20);
        make.bottom.equalTo(self.titleLabel).offset(-1);
        make.width.equalTo(220);
    }];
    
    [self.view addSubview:self.companyLabel];
    [self.companyLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(51);
    }];
    
    [self.view addSubview:self.companyTextField];
    [self.companyTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.companyLabel.mas_right).offset(20);
        make.bottom.equalTo(self.companyLabel).offset(-1);
        make.width.equalTo(220);
    }];
    
    [self.view addSubview:self.emailLabel];
    [self.emailLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.companyLabel);
        make.top.equalTo(self.companyLabel.mas_bottom).offset(51);
    }];
    
    [self.view addSubview:self.emailTextField];
    [self.emailTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.emailLabel.mas_right).offset(20);
        make.bottom.equalTo(self.emailLabel).offset(-1);
        make.width.equalTo(220);
    }];
    
    [self.view addSubview:self.locationLabel];
    [self.locationLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.emailLabel);
        make.top.equalTo(self.emailLabel.mas_bottom).offset(51);
    }];
    
    [self.view addSubview:self.locationTextFiled];
    [self.locationTextFiled makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.locationLabel.mas_right).offset(20);
        make.bottom.equalTo(self.locationLabel).offset(-1);
        make.width.equalTo(220);
    }];
}


#pragma mark - Private
- (void)rightBarItemClick:(UIBarButtonItem *)item
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Lazy loading
-(UIImageView *) headerImageView
{
    if (!_headerImageView)
    {
        _headerImageView = [UIImageView new];
        
        [_headerImageView yy_setImageWithURL:[NSURL URLWithString:ACCOUNT.account.head_pic] placeholder:UIImageMake(@"contact_defaultHead")];;
        _headerImageView.contentMode = UIViewContentModeCenter;
        [_headerImageView sizeToFit];
    }
    return _headerImageView;
}

-(UIButton *) headerEditButton
{
    if(!_headerEditButton)
    {
        _headerEditButton = [[UIButton alloc] init];
        [_headerEditButton setImage:UIImageMake(@"user_info_edit") forState:UIControlStateNormal];
        _headerEditButton.layer.masksToBounds = YES;
    }
    return _headerEditButton;
}

-(UILabel *) familyNameLabel
{
    if(!_familyNameLabel)
    {
        _familyNameLabel = [UILabel new];
        
        [_familyNameLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"姓";
        }];
        
        [_familyNameLabel sizeToFit];
    }
    return _familyNameLabel;
}

-(UITextField *) familyNameTextField
{
    if(!_familyNameTextField)
    {
        _familyNameTextField = [[UITextField alloc]init];
        _familyNameTextField.keyboardType = UIKeyboardTypeDefault;
        
        [_familyNameTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_familyNameTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(80);
            make.top.equalTo(_familyNameTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _familyNameTextField;
}


-(UILabel *) lastNameLabel
{
    if(!_lastNameLabel)
    {
        _lastNameLabel = [UILabel new];
        
        [_lastNameLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"名";
        }];
        
        [_lastNameLabel sizeToFit];
    }
    return _lastNameLabel;
}

-(UITextField *) lastNameTextField
{
    if(!_lastNameTextField)
    {
        _lastNameTextField = [[UITextField alloc]init];
        _lastNameTextField.keyboardType = UIKeyboardTypeDefault;
        
        [_lastNameTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_lastNameTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(80);
            make.top.equalTo(_lastNameTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _lastNameTextField;
}

-(UILabel *) titleLabel
{
    if(!_titleLabel)
    {
        _titleLabel = [UILabel new];
        
        [_titleLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"职位";
        }];
        
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

-(UITextField *) titleTextField
{
    if(!_titleTextField)
    {
        _titleTextField = [[UITextField alloc]init];
        _titleTextField.keyboardType = UIKeyboardTypeDefault;
        
        [_titleTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_titleTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(220);
            make.top.equalTo(_titleTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _titleTextField;
}

-(UILabel *) companyLabel
{
    if(!_companyLabel)
    {
        _companyLabel = [UILabel new];
        
        [_companyLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"公司";
        }];
        
        [_companyLabel sizeToFit];
    }
    return _companyLabel;
}

-(UITextField *) companyTextField
{
    if(!_companyTextField)
    {
        _companyTextField = [[UITextField alloc]init];
        _companyTextField.keyboardType = UIKeyboardTypeDefault;
        
        [_companyTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_companyTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(220);
            make.top.equalTo(_companyTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _companyTextField;
}

-(UILabel *) emailLabel
{
    if(!_emailLabel)
    {
        _emailLabel = [UILabel new];
        
        [_emailLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"邮箱";
        }];
        
        [_emailLabel sizeToFit];
    }
    return _emailLabel;
}

-(UITextField *) emailTextField
{
    if(!_emailTextField)
    {
        _emailTextField = [[UITextField alloc]init];
        _emailTextField.keyboardType = UIKeyboardTypeDefault;
        
        [_emailTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_emailTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(220);
            make.top.equalTo(_emailTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _emailTextField;
}

-(UILabel *) locationLabel
{
    if(!_locationLabel)
    {
        _locationLabel = [UILabel new];
        
        [_locationLabel setStyle:^(UIView *target) {
            UILABELSTYLE;
            temp.font = UIThinFontMake(24);
            temp.textColor = UIColorMake(82, 82, 82);
            temp.textAlignment = NSTextAlignmentLeft;
            temp.text = @"地点";
        }];
        
        [_locationLabel sizeToFit];
    }
    return _locationLabel;
}

-(UITextField *) locationTextFiled
{
    if(!_locationTextFiled)
    {
        _locationTextFiled = [[UITextField alloc]init];
        _locationTextFiled.keyboardType = UIKeyboardTypeDefault;
        
        [_locationTextFiled setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(18);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_locationTextFiled addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(220);
            make.top.equalTo(_locationTextFiled.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _locationTextFiled;
}
@end
